<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="/pages/template.xhtml">
<body>
<ui:define name="content">
<f:view>
	<h:form>
	<rich:toolBar binding="#{menuMB.menuBar}"/> 
		<h:messages/>
		 <fieldset>
	        <legend>Manter Estabelecimento - Pesquisar</legend>
			<h:panelGrid columns="2">
			
			    <h:outputLabel for="nomeLabel" value="Estabelecimento:" />
				<h:inputText id="nomeInput" value="#{estabelecimentoMB.estabelecimentoTO.nmEstabelecimento}" style=" width : 321px;" />
				
				<h:outputLabel value="UF:" for="idUf" />
                    <h:selectOneMenu  label="UF" id="idUf" value="#{estabelecimentoMB.estabelecimentoTO.idUf}" rendered="true">
                    	<f:selectItem itemValue="" itemLabel="Selecione..." />
                        <f:selectItems value="#{estabelecimentoMB.cbxUfs}"/>
                        <a4j:support event="onchange" ajaxSingle="true" action="#{estabelecimentoMB.carregarCidadesPorIdUf}" reRender="idUf, idCidade"/>
                    </h:selectOneMenu>
                     
                     
                    <h:outputLabel value="Cidade:" for="idCidade" />
                    <h:selectOneMenu label="Cidade" id="idCidade" value="#{estabelecimentoMB.estabelecimentoTO.idCidade}"  rendered="true">
                    	<f:selectItem itemValue="" itemLabel="Selecione..." />
                        <f:selectItems value="#{estabelecimentoMB.cbxCidades}"/>
                        <a4j:support event="onchange" ajaxSingle="true" action="#{estabelecimentoMB.carregarBairrosPorIdCidade}" reRender="idUf, idCidade, idBairro"/>
                    </h:selectOneMenu>
                    
                   <h:outputLabel value="Ativo:" for="inAtivo" />
                    <h:selectOneMenu label="Ativo" id="inAtivo" value="#{estabelecimentoMB.estabelecimentoTO.inAtivo}">
                    	<f:selectItem itemValue="" itemLabel="Selecione..." />
                        <f:selectItems value="#{estabelecimentoMB.carregarSimNao}"/>
                    </h:selectOneMenu>
				
    		</h:panelGrid>
    		    <h:panelGroup  styleClass="alignRight">
      				<h:commandButton value="Pesquisar" action="#{estabelecimentoMB.pesquisarPorFiltro}" styleClass="botoes"/>
    			</h:panelGroup>
				<rich:spacer height="10" />
			<rich:dataTable id="tableSearch" value="#{estabelecimentoMB.listEstabelecimento}" var="estabelecimento"  rowKeyVar="row" rows="4"  rendered="#{not empty estabelecimentoMB.listEstabelecimento}" reRender="ds">
					<f:facet name="header" >
            		<h:outputText styleClass="alignRight" value="Quantidade de registros encontrados: #{estabelecimentoMB.qtdLinhas}"/>
        			</f:facet>
				      <rich:column sortBy="#{estabelecimento.nmEstabelecimento}">
				         <f:facet name="header">Name</f:facet>
					    <h:outputText id="nmEstabelecimento" value="#{estabelecimento.nmEstabelecimento}" />
					 </rich:column>
	 
				      <rich:column sortBy="#{estabelecimento.nmUf}">
				         <f:facet name="header">UF</f:facet>
				         <h:outputText id="nmUf" value="#{estabelecimento.nmUf}"/>
				      </rich:column>
				      
				      <rich:column sortBy="#{estabelecimento.nmCidade}">
				         <f:facet name="header">Cidade</f:facet>
				         <h:outputText id="nmCidade" value="#{estabelecimento.nmCidade}"/>
				      </rich:column>
				      
				      <rich:column sortBy="#{estabelecimento.nmBairro}">
				         <f:facet name="header">Bairro</f:facet>
				         <h:outputText id="dsBairro" value="#{estabelecimento.nmBairro}"/>
				      </rich:column>
				      
				      <rich:column sortBy="#{estabelecimento.nmLogradouro}">
				         <f:facet name="header">Logradouro</f:facet>
				         <h:outputText id="dsEndereco"   value="#{estabelecimento.nmLogradouro}"/>
				      </rich:column>
				      
				      <rich:column sortBy="#{estabelecimento.nuEstabelecimento}">
				         <f:facet name="header">Numero</f:facet>
				         <h:outputText id="nuComplemento"   value="#{estabelecimento.nuEstabelecimento}"/>
				         
				      </rich:column>
				      
				      <rich:column sortBy="#{estabelecimento.nuTelefone}">
				         <f:facet name="header">Telefone</f:facet>
				         <h:outputText id="nuTelefone"   value="#{estabelecimento.nuTelefone}">
				         </h:outputText>
				         
				      </rich:column>
				      
				      <rich:column sortBy="#{estabelecimento.dsEstabelecimento}">
				         <f:facet name="header">Descricao</f:facet>
				         <h:outputText id="dsDescricao"   value="#{estabelecimento.dsEstabelecimento}"/>
				      </rich:column>
				      
				      <rich:column sortBy="#{estabelecimento.inAtivo}">
				         <f:facet name="header">Ativo</f:facet>
				         <h:outputText id="inAtivo"   value="#{estabelecimento.inAtivo}"/>
				      </rich:column>
				      
				      <rich:column >
				      		<f:facet name="header"> Editar </f:facet>
							<a4j:commandLink   id="show" ajaxSingle="true" reRender="inputsAlterar" action="#{estabelecimentoMB.iniciarAlterarEstabelecimento}">
							<h:graphicImage value="/images/edit.gif"/>
							<f:setPropertyActionListener  value="#{estabelecimento}" target="#{estabelecimentoMB.estabelecimentoTO}"/>
							</a4j:commandLink >
							<rich:toolTip for="show" value="Editar" />
					</rich:column>
				      <rich:column >
				      		<f:facet name="header"> Excluir </f:facet>
							<a4j:commandLink  ajaxSingle="true" id="deleta" 
							oncomplete="#{rich:component('deletePanel')}.show()"
							status="sts">
							<h:graphicImage value="/images/delete.png"/>
							<f:setPropertyActionListener  value="#{row}" target="#{estabelecimentoMB.row}"/>
							<f:setPropertyActionListener  value="#{estabelecimento}" target="#{estabelecimentoMB.estabelecimentoTO}"/>
							</a4j:commandLink >
							 <rich:toolTip for="deleta" value="Remover" />
					</rich:column>
		               <f:facet name="footer">
		                <rich:datascroller id="ds"></rich:datascroller>
		              </f:facet>
</rich:dataTable>
			<rich:spacer height="10"/>
			<h:panelGroup  styleClass="alignRight">
				<h:commandButton value="Incluir" action="#{estabelecimentoMB.iniciarEstabelecimento}" styleClass="botoes"/>
				<h:commandButton value="Cancelar" immediate="true" action="#{estabelecimentoMB.voltar}" styleClass="botoes"/>
    		</h:panelGroup>

			 <a4j:region id="regiaoAjax">
			 	<a4j:status id="sts">
	            	<f:facet name="start">
	            		<h:graphicImage value="/images/ajax-loader.gif" />
	               	</f:facet>
	            </a4j:status>
	         </a4j:region>
	    </fieldset>
	</h:form>
	
	
	    <rich:modalPanel id="deletePanel" autosized="true" width="200">
        <f:facet name="header">
            <h:outputText value="Deseja realmente remover esse registro?"
                style="padding-right:15px;" />
        </f:facet>
        <f:facet name="controls">
            <h:panelGroup>
                <h:graphicImage value="/images/delete.png"
                    styleClass="hidelink" id="hidelink2" />
                <rich:componentControl for="deletePanel" attachTo="hidelink2"
                    operation="hide" event="onclick" />
            </h:panelGroup>
        </f:facet>
        <h:form>
            <table width="100%">
                <tbody>
                    <tr>
                        <td align="center" width="50%">
	                        	<a4j:commandButton value="Yes"
	                        	ajaxSingle="true"
	                            action="#{estabelecimentoMB.remover}"
	                            reRender="tableSearch" oncomplete="#{rich:component('deletePanel')}.hide();" />
                            </td>
                        <td align="center" width="50%">
                        	<a4j:commandButton
                            value="Cancel"
                            onclick="Richfaces.hideModalPanel('deletePanel');"/>
                        </td>
                    </tr>
                </tbody>
            </table>
        </h:form>
    </rich:modalPanel>
    
</f:view>
</ui:define>
</body>
</ui:composition >
